<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="阶段" prop="stage">
        <el-input
          v-model="queryParams.stage"
          placeholder="请输入阶段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月份" prop="month">
        <el-input
          v-model="queryParams.month"
          placeholder="请输入月份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级名称" prop="className">
        <el-input
          v-model="queryParams.className"
          placeholder="请输入班级名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['teaching:investigate:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="investigateList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="所属阶段" align="center" prop="stage" />
      <el-table-column label="月份" align="center" prop="month" />
      <el-table-column label="班级名称" align="center" prop="className" />
      <el-table-column label="反馈人数" align="center" prop="peopleNum" />
      <el-table-column label="教师提交状态" align="center" prop="status" />
      <el-table-column label="创建日期" align="center" prop="createTime" />
      <el-table-column label="修改日期" align="center" prop="updateTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['teaching:investigate:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['teaching:investigate:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleDetail(scope.row)"
            v-hasPermi="['teaching:investigate:query']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改阶段问卷对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="班级名称" prop="className">
          <el-select v-model="form.className"  placeholder="请选择班级"  >
            <el-option v-for="(item, index) in classesList" :key="index" :label="item.className"
                       :value="item.className" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="阶段" prop="stage">
          <el-select v-model="form.stage" placeholder="请选择阶段" clearable>
            <el-option
              v-for="dict in dict.type.sys_stage"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="月份" prop="month">
          <el-select v-model="form.month" placeholder="请选择月份" clearable>
            <el-option label="第一月" :value="1"></el-option>
            <el-option label="第二月" :value="2"></el-option>
            <el-option label="第三月" :value="3"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog title="学生提交详情" :visible.sync="xopen" width="80%" append-to-body>
      <el-table v-loading="loading" :data="stage_investigate_detailList">
        <el-table-column label="id" align="center" prop="id" />
        <el-table-column label="学生姓名" align="center" prop="studentName" />
        <el-table-column label="所属阶段" align="center" prop="stage" />
        <el-table-column label="月份" align="center" prop="month" />
        <el-table-column label="自评-学习态度" align="center" prop="evaluateStudy" />
        <el-table-column label="自评-努力态度" align="center" prop="evaluateEfforts" />
        <el-table-column label="自评-表达态度" align="center" prop="evaluateDeliver" />
        <el-table-column label="反馈状态" align="center" prop="feedbackStatus" />
        <el-table-column label="创建人" align="center" prop="createBy" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleTeacherUpdate(scope.row)"
              v-hasPermi="['teaching:stage_investigate_detail:edit']"
            >填写</el-button>
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport(scope.row)"
              v-hasPermi="['teaching:stage_investigate_detail:export']"
            >导出</el-button>
          </template>
        </el-table-column>
      </el-table>

    </el-dialog>
    <el-dialog title="提交详情" :visible.sync="topen" width="80%" append-to-body>
      <el-form ref="teacherform" :model="teacherform" :rules="rules" label-width="30%">
        <el-form-item label="学生姓名" prop="studentName">
          <el-input v-model="teacherform.studentName" placeholder="请输入学生姓名" disabled/>
        </el-form-item>
        <el-form-item label="所属阶段" prop="stage">
          <el-select v-model="teacherform.stage" placeholder="请选择阶段" disabled>
            <el-option
              v-for="dict in dict.type.sys_stage"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"

            />
          </el-select>
        </el-form-item>
        <el-form-item label="月份" prop="month">
          <el-input v-model="teacherform.month" placeholder="请输入月份" disabled/>
        </el-form-item>
        <el-form-item label="自评-学习态度" prop="evaluateStudy">
          <el-select v-model="teacherform.evaluateStudy" placeholder="请选择" clearable>
            <el-option
              v-for="dict in dict.type.ya_learn_attitude"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="自评-努力态度" prop="evaluateEfforts">
          <el-select v-model="teacherform.evaluateEfforts" placeholder="请选择" clearable>
            <el-option
              v-for="dict in dict.type.ya_effort"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="自评-表达态度" prop="evaluateDeliver">
          <el-select v-model="teacherform.evaluateDeliver" placeholder="请选择" clearable>
            <el-option
              v-for="dict in dict.type.ya_expression"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="学生自己填写的存在问题" prop="studentProblem">
          <el-input v-model="teacherform.studentProblem" placeholder="请输入学生自己填写的存在问题" disabled/>
        </el-form-item>
        <el-form-item label="学生自己填写改进的问题" prop="studentImprove">
          <el-input v-model="teacherform.studentImprove" placeholder="请输入学生自己填写改进的问题" disabled/>
        </el-form-item>
        <el-form-item label="学生自己填写的加强的技能" prop="studentSkill">
          <el-input v-model="teacherform.studentSkill" placeholder="请输入学生自己填写的加强的技能" disabled/>
        </el-form-item>
        <el-form-item label="学生自己填写的提供的帮助" prop="studentHelp">
          <el-input v-model="teacherform.studentHelp" placeholder="请输入学生自己填写的提供的帮助" disabled/>
        </el-form-item>
        <el-form-item label="老师自己填写的学生存在的问题" prop="teacherProblem">
          <el-input v-model="teacherform.teacherProblem" placeholder="请输入老师自己填写的学生存在的问题" />
        </el-form-item>
        <el-form-item label="老师自己填写的学生改进的地方" prop="teacherImprove">
          <el-input v-model="teacherform.teacherImprove" placeholder="请输入老师自己填写的学生改进的地方" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTeacherForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { listInvestigate, getInvestigate, delInvestigate, addInvestigate, updateInvestigate } from "@/api/teaching/investigate";
import {listAllClasses} from "@/api/teaching/classes";
import { selectInvestigate,getStage_investigate_detail,updateStage_investigate_detail} from "@/api/teaching/stage_investigate_detail";
export default {
  dicts: ['sys_stage','ya_attendance_status','ya_weekday','ya_task_status','ya_task_qualified'],
  name: "Investigate",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 阶段问卷表格数据
      investigateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,// 是否显示弹出层
      xopen: false,
      topen:false,
      // 查询参数
      queryParams: {
        id:null,
        pageNum: 1,
        pageSize: 10,
        stage: null,
        month: null,
        className: null,
        peopleNum: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },

      classesList: [],
      // 阶段问卷细节表格数据
      stage_investigate_detailList: [],
      teacherform:{}
    };
  },
  created() {
    this.getList();
    this.getClassesList();
  },
  methods: {
    getClassesList() {
      listAllClasses().then(response => {
        this.classesList = response.rows;
      });
    },
    /** 查询阶段问卷列表 */
    getList() {
      this.loading = true;
      listInvestigate(this.queryParams).then(response => {
        this.investigateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stage: null,
        month: null,
        className: null,
        peopleNum: null,
        createBy: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加阶段问卷";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInvestigate(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改阶段问卷";
      });
    },
    /** 修改按钮操作 */
    handleTeacherUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStage_investigate_detail(id).then(response => {
        this.teacherform = response.data;
        this.topen = true;
        this.title = "提交教师阶段问卷";
      });
    },
    /**详情*/
    handleDetail(row){
      this.xopen = true;
      selectInvestigate().then(response => {
        console.log("aaa:"+response)
        this.stage_investigate_detailList = response.rows;
        this.loading = false;
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInvestigate(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInvestigate(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitTeacherForm() {
      this.$refs["teacherform"].validate(valid => {
        if (valid) {
            updateStage_investigate_detail(this.teacherform).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.topen = false;
              // this.xopen = false;
              this.getList();
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除阶段问卷编号为"' + ids + '"的数据项？').then(function() {
        return delInvestigate(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport(row) {
      console.log("mmm:"+row)
     this.queryParams.id = row.id;
      this.download('teaching/stage_investigate_detail/export', {
        ...this.queryParams
      }, `investigate_${new Date().getTime()}.xls`)
    }
  }
};
</script>
